<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/5/25.
 */

namespace App\Http\Request\System;

use App\Models\System;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class SystemRequest extends FormRequest
{
    public function rules(): array
    {
        $id = (int) $this->route('id');

        return [
            'username' => ['required', 'max:255', Rule::unique(System::class)->ignore($id)],
            'nickname' => ['required', 'max:255'],
            'password' => [
                Rule::requiredIf(function () use ($id) {
                    return 0 === $id;
                }),
                'max: 255',
            ],
            'mobile' => 'max:20',
            'avatar' => 'max:255',
        ];
    }
}
